<template>
    <div >
      <div class="hd">
        <span @click="$router.go(-1)"> 返回 </span>
        充值
      </div>
      <div class="ctct" >
        <md-field>
          <md-input-item
            title="充值金额"
            type="money"
            v-model="money"
            placeholder="输入您充值的金额"
          ></md-input-item>
        </md-field>
        <md-button @click="tocharge">下一步</md-button>
      </div>

    </div>
</template>

<script>
import { Toast } from 'mand-mobile'
export default {
  name: 'Account',
  data () {
    return {
      ad: {
        title: '',
        content: '',
        money: ''
      }
    }
  },
  beforeMount: async function () {

  },
  methods: {
    async tocharge () {
      let _res = await this.$api.post('/addCharge', {
        fee: this.money,
        openid: this.$store.state.wxuser.openid
      })

      let orderinfo = _res.data.data

      let _payparams = await this.$api.post('/prepay', {
        oid: 'cid_' + orderinfo.id,
        total_fee: parseFloat(this.money * 100),
        // total_fee: 1,
        desc: this.$store.state.wxuser.nickname + '的充值订单',
        openid: this.$store.state.wxuser.openid
      })

      if (_payparams.data.state) {
        const _this = this
        WeixinJSBridge.invoke(
          'getBrandWCPayRequest', _payparams.data.data,
          function (res) {
            if (res.err_msg === 'get_brand_wcpay_request:ok') {
              // 使用以上方式判断前端返回,微信团队郑重提示：
              // res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
              Toast.succeed('支付成功')
              setTimeout(() => {
                this.$router.go(-1)
              }, 2000)
            }
          })
      }
    }
  }
}
</script>

<style scoped>
  .br{
    border:1px solid red
  }
  .actop{
    height: 60px;
    padding:30px 20px 20px;
    border-bottom:2px solid #e9e9e9
  }

  .avt{
    height: 60px;
    width: 60px;
    box-sizing: border-box;
    border-radius: 50%;
    position: relative;
  }
  .avt > img{
    width: 100%;
    border-radius: 50%;
  }
  .acname{
    font-weight: 500;
    font-size: 25px;
    color:#666;
  }
  .acname + span{
    font-size: 12px;
    color:#999
  }
.aczone{
  padding:10px 20px
}
  .acitem{
    padding:10px 0px;
    border-bottom:1px solid #e9e9e9;
    color:#666;
    position: relative;
    font-size: 16px;
  }
.acitem span{
  display: block;
  font-size: 12px;
  line-height:20px;
  color:#999
}
  .acitem .fr{
    font-size: 14px;
    padding-top: 10px;
  }
  #qrcode{
    width: 30px;
    height: 30px;
    position: absolute;
    top:50%;
    transform: translateY(-50%);
    left:70px
  }
  .acitem .mr{
    color:orangered;
    font-size: 14px;
  }
  .ctct{
    padding:10px 15px
  }
</style>
